import React from 'react';
import axios from 'axios';
import ReactDOM from 'react-dom';
import './less/index.less';
import App from './App';
/******调用redux相关组件*****/
import {Provider} from 'react-redux';
import { createStore } from 'redux'
/******调用redux相关组件 end*****/
import registerServiceWorker from './registerServiceWorker';

import {
    BrowserRouter as Router,
} from 'react-router-dom'
//超时时间
axios.defaults.timeout = 5000;

axios.defaults.retry = 1; //重试次数
axios.defaults.retryDelay = 1000;//重试延时
axios.defaults.shouldRetry = (error) => true;//重试条件，默认只要是错误都需要重试


// http请求拦截器 start
axios.interceptors.request.use(config => {
    //axios.defaults.headers.common['token'] = "aaaaaaa2222222";
    //console.log("我是请求的拦截")
    return config
}, error => {
    return Promise.reject(error)
});

// http响应拦截器
axios.interceptors.response.use(data => {
    // 响应成功关闭loading
    //console.log("我是响应的拦截")
    return data
}, error => {
    return Promise.reject(error)
});

console.log(process.env)
/*
定义全局变量
*/
window.aa="ss"

/********  Reducer store *****************/

// Reducer
function counter(state = { count: 0,status:true }, action) {
    const count = state.count
    console.log(state)
    switch (action.type) {
        case 'increase':
            {
                state.count=state.count+1
                state.status=!state.status
                 return {...state}
            }
        case 'desc':
            return { count: count - 1,status:true }
        case 'other':
        {   state.newField="乱七八糟"
            return {...state}
        }

        default:
            return state
    }
}

// Store
const store = createStore(counter)

/********  Reducer end *****************/




ReactDOM.render(
    <Provider store={store}>
        <Router><App /></Router>
        </Provider>, document.getElementById('root'));
registerServiceWorker();
